﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ServiceRanking
{
    abstract class VeryLargeList<T> : IList<T>
    {
        string tempPath = "";
        string name = Guid.NewGuid().ToString();
        bool isCreate = false;

        public VeryLargeList()
        {
        }

        public int IndexOf(T item)
        {
            throw new NotImplementedException();
        }

        public void Insert(int index, T item)
        {
            throw new NotImplementedException();
        }

        public void RemoveAt(int index)
        {
            throw new NotImplementedException();
        }

        public T this[int index]
        {
            get
            {
                List<T> list = readList(tempPath + name);
                return list[index];
            }
            set
            {
                List<T> list = readList(tempPath + name);
                list[index] = value;
                writeList(list, tempPath + name);
            }
        }

        public void Add(T item)
        {
            if (!isCreate)
            {
                List<T> list = new List<T>();
                list.Add(item);
                writeList(list, tempPath + name);
            }
            else
            {
                List<T> list = readList(tempPath + name);
                list.Add(item);
                writeList(list, tempPath + name);
            }
        }

        public void Clear()
        {
        }

        public bool Contains(T item)
        {
            throw new NotImplementedException();
        }

        public void CopyTo(T[] array, int arrayIndex)
        {
            throw new NotImplementedException();
        }

        public int Count
        {
            get
            {
                int c = 0;
                if (!isCreate)
                {
                    List<T> list = new List<T>();
                    c = list.Count;
                    writeList(list, tempPath + name);
                }
                return c;
            }
        }

        public bool IsReadOnly
        {
            get { throw new NotImplementedException(); }
        }

        public bool Remove(T item)
        {
            throw new NotImplementedException();
        }

        public IEnumerator<T> GetEnumerator()
        {
            throw new NotImplementedException();
        }
        public void ggg() { }
        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            throw new NotImplementedException();
        }

        protected abstract void writeList(List<T> list, string listName);
        
            // string fileName = tempPath + listName;
            // using (BinaryWriter binWriter =
            //new BinaryWriter(File.Open(fileName, FileMode.Create)))
            // {
            //     //foreach (T item in list)
            //     //    binWriter.Write(item);
            // }


        protected abstract List<T> readList(string listName);


    }
}
